#include <iostream>
#include <algorithm>

using namespace std;

const int N = 2510;

int n, m;
struct node
{
	int x; // 左区间 / 阳光强度
	int y; // 右区间 / 数量
}a[N], b[N];


bool cmp(node& x, node& y)
{
	return x.x > y.x;
}

int main()
{
	cin >> n >> m;
	for(int i = 1; i <= n; i++) cin >> a[i].x >> a[i].y;
	for(int i = 1; i <= m; i++) cin >> b[i].x >> b[i].y;

	sort(a + 1, a + 1 + n, cmp); // 按照左端点从大到小排序
	sort(b + 1, b + 1 + m, cmp); // 按照阳光强度从大到小排序

	int ret = 0;
	for(int i = 1; i <= n; i++)
	{
		int l = a[i].x, r = a[i].y;
		//按照从大到小的顺序分配奶牛
		for(int j = 1; j <= m; j++)
		{
			int w = b[j].x, &cnt = b[j].y;
			if(cnt == 0) continue;
			if(w < l) break;
			if(w > r) continue; // 找下一头奶牛
			//l <= w <= r
			ret++;
			cnt--;
			break;
		}
	}

	cout << ret << endl;

	return 0;
}

